package com.e_manager.soft.emanager.controller;

import com.e_manager.soft.emanager.annotation.Authorization;
import com.e_manager.soft.emanager.annotation.BaseController;
import com.e_manager.soft.emanager.annotation.CurrentUser;
import com.e_manager.soft.emanager.entity.InvitationRecord;
import com.e_manager.soft.emanager.entity.User;
import com.e_manager.soft.emanager.resultMsg.ResultConstant;
import com.e_manager.soft.emanager.resultMsg.ResultInfo;
import com.e_manager.soft.emanager.service.InvitationRecordService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * [InvitationRecordController]<br>
 * 邀请记录信息<br>
 * <br>
 * [功能概要]<br>
 * 邀请记录信息<br>
 * <br>
 * [更新履历]<br>
 * 2018/04/03 ver1.00 JYS CORPORATION<br>
 *
 * @author JYS CORPORATION
 * @version 1.00
 */
@BaseController
@Authorization
@Api(value = "邀请记录", description = "邀请记录")
public class InvitationRecordController {
    @Autowired
    private InvitationRecordService invitationRecordService;

    @ApiOperation(value = "创建", notes = "插入邀请记录")
    @PostMapping(value = "/invitationRecord", produces = {"application/json;charset=utf-8"})
    public ResultInfo<?> save(@ApiParam(required = true, value = "需要参数:新增对象") @RequestBody InvitationRecord invitationRecord, @CurrentUser User iuser) {
        ResultInfo info = new ResultInfo<>();
        //保存数据
        invitationRecord.setCreateUser(iuser.getUserID());
        invitationRecord.setUserID(iuser.getUserID());
        info = invitationRecordService.save(invitationRecord);
        return info;
    }

    @ApiOperation(value = "获取邀请记录列表", notes = "获取邀请记录列表")
    @RequestMapping(value = "/invitationRecords", produces = {"application/json;charset=utf-8"})
    public ResultInfo<?> findAll(@RequestBody InvitationRecord invitationRecord, @CurrentUser User iuser) {
        PageInfo<InvitationRecord> pageInfo = null;
        ResultInfo resultInfo = new ResultInfo();
        try {
            //初始化对象
            invitationRecord.setUserID(iuser.getUserID());
            //分页列表
            pageInfo = invitationRecordService.findAllByPage(invitationRecord);
            //返回信息
            resultInfo.setMsg(ResultConstant.SUCCESS.getMessage());
            resultInfo.setData(pageInfo);
            resultInfo.setCode(ResultConstant.SUCCESS.getCode());
        } catch (Exception e) {
            resultInfo.setMsg(ResultConstant.FAIL.getMessage());
            resultInfo.setCode(ResultConstant.FAIL.getCode());
            e.printStackTrace();
        }
        return resultInfo;
    }
}

